package losrebellos.lospistoleros.vo 
{
	import flash.display.Stage;
	import flash.geom.Rectangle;

	/*
	 *
	 * @author los rebellos - ben@benoitvinay.com
	 *
	 */
	public class ResizeRectangleVO extends Rectangle 
	{
		/*
		 *
		 * CONSTANTS
		 *
		 */
		public static const UNIT_PERCENT:String			= "unit/percent";
		public static const UNIT_PIXEL:String			= "unit/pixel";
		
		
		/*
		 *
		 * VARIABLES
		 *
		 */
		public var unit:String;
		
		
		/*
		 *
		 * CONSTRUCTOR
		 *
		 */
		public function ResizeRectangleVO(x:Number = 0, y:Number = 0, width:Number = 1, height:Number = 1, unit:String = UNIT_PERCENT)
		{
			this.unit = unit;
			
			super(x, y, width, height);
		}
		
		
		/*
		 * 
		 * CALCULATION
		 * 
		 */
		public function getRectangleFromStage(stage:Stage):Rectangle
		{
			switch(unit)
			{
				case UNIT_PIXEL:
					return this;
					break;
				
				case UNIT_PERCENT:
					return new Rectangle(this.x * stage.stageWidth, this.y * stage.stageHeight, this.width * stage.stageWidth, this.height * stage.stageHeight);
					break;
			}
			
			return null;
		}
		
		
		/*
		 * 
		 * UTILS
		 * 
		 */
		override public function clone():Rectangle
		{
			return new ResizeRectangleVO(this.x, this.y, this.width, this.height, this.unit);
		}
	}
}